<?php
declare(strict_types=1);

namespace app\admin\service;

use app\admin\model\Withdraw as WithdrawModel;

class WithdrawService
{
    /**
     * 提现记录
     * @param $where
     * @param $page
     * @param $pagesize
     * @return array
     */
    public static function getWithdrawList($where, $page, $pagesize)
    {
        $data = WithdrawModel::getWithdrawList($where, $page, $pagesize);
        foreach ($data as $k => $v) {
            switch ($v['status']) {
                case 1:
                    $data[$k]['status_name'] = '已打款';
                    $times = '打款：' . date('Y-m-d H:i', $v['remit_time']);
                    break;
                case 2:
                    $data[$k]['status_name'] = '已驳回';
                    $times = '驳回：' . date('Y-m-d H:i', $v['reject_time']);
                    break;
                default:
                    $data[$k]['status_name'] = '审核中';
                    $times = '-';
            }

            $data[$k]['date'] = '申请：' . date('Y-m-d H:i', strtotime($v['create_time'])) . '<br>' . $times;
        }

        return $data;
    }

    /**
     * 统计提现记录
     * @param $where
     * @return int
     */
    public static function countWithdrawList($where)
    {
        return WithdrawModel::countWithdrawList($where);
    }

    /**
     * 指定提现记录
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findWithdraw($where)
    {
        return WithdrawModel::findWithdraw($where);
    }

    /**
     * 更新提现记录
     * @param $where
     * @param $data
     * @return WithdrawModel
     */
    public static function updateWithdraw($where, $data)
    {
        return WithdrawModel::updateWithdraw($where, $data);
    }
}